package com.vtuzx.kingdee.xqc_batch.component;

import com.vtuzx.batch.component.IVtuzxBatchComponent;
import com.vtuzx.core.bean.dto.VtuzxMap;
import com.vtuzx.core.utils.VtuzxUtil;
import com.vtuzx.kingdee.xqc_core.service.IVtuzxBasicService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

@Component("sync_payment")
public class SyncPayment implements IVtuzxBatchComponent {
    /** Logger */
    private static final Logger _logger = LoggerFactory.getLogger(SyncPayment.class);

    @Autowired
    private IVtuzxBasicService basicService;

    /**
     * 自动同步吉克云收款单并传到金蝶
     *
     * @param param 入参
     */
    @Override
    public void execute(VtuzxMap param) throws Exception {
        String startDate = VtuzxUtil.getString(param, "from");
        int month = VtuzxUtil.getInt(param, "month",1);
        Date from;
        Date to;
        Date now = new Date();
        if (VtuzxUtil.isEmpty(startDate)) {
            from = VtuzxUtil.calcDate(now, Calendar.MONTH, -month);
            to = now;
        } else {
            from = VtuzxUtil.parseDate(startDate);
            to = VtuzxUtil.calcDate(from, Calendar.MONTH, month);
        }
        _logger.info(String.format("导入%s - %s的数据", VtuzxUtil.formatYmdHmsF(from), VtuzxUtil.formatYmdHmsF(to)));
        basicService.syncPayment(from, to, 0);
    }
}
